const { object } = require("joi")

const $ = {
  /**
   * 相同值合并，不同值组成数组连接在后
   * 
   * 
   */
  CombineData(result,arr){
    let ind = arr[0]
    let array = []
    let obj = {}
    let data = []
    let count = 0
    result.forEach((v,i)=>{
      let redetalisObj = {}
      if(!array.includes(v[ind])){
        if(obj&&Object.keys(obj).length!=0){
          data.push(obj)
        }
        obj={}
        array.push(v[ind])
        for(let value of arr){
          obj[value] = v[value]
        }
        obj.redetalis = []
      }
      for(let k in v){
        if(!arr.includes(k)){
          redetalisObj[k]=v[k]
        }
      }
      obj.redetalis.push(redetalisObj)
      if(i==result.length-1) data.push(obj)
    })
    return data
  }
}
module.exports = $